package com.ss.android.article.base.feature.detail2.view;

import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;

import android.animation.Animator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.Dialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bytedance.article.common.c.JSONObjectWrapper;
import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.UIUtils;
import com.bytedance.frameworks.a.a.b;
import com.bytedance.frameworks.base.mvp.Presenter;
import com.ss.android.action.a.a.Comment;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.app.schema.AdsAppActivity;
import com.ss.android.article.base.feature.detail.model.ArticleDetail;
import com.ss.android.article.base.feature.detail.model.ArticleInfo;
import com.ss.android.article.base.feature.detail.presenter.ActivityStackManager;
import com.ss.android.article.base.feature.detail.presenter.ActivityStackManager.Type;
import com.ss.android.article.base.feature.detail2.SSPage;
import com.ss.android.article.base.feature.detail2.article.NewArticleDetailFragment;
import com.ss.android.article.base.feature.detail2.d.NewDetailContext;
import com.ss.android.article.base.feature.detail2.e.NewDetailPresenter;
import com.ss.android.article.base.feature.detail2.e.a.CommonBizInteractor;
import com.ss.android.article.base.feature.detail2.picgroup.GalleryFragment;
import com.ss.android.article.base.feature.detail2.video.NewVideoDetailFragment;
import com.ss.android.article.base.feature.detail2.widget.DeleteView;
import com.ss.android.article.base.feature.detail2.widget.DetailErrorView;
import com.ss.android.article.base.feature.detail2.widget.DetailStyle;
import com.ss.android.article.base.feature.detail2.widget.DetailTitleBar;
import com.ss.android.article.base.feature.detail2.widget.DetailToolBar;
import com.ss.android.article.base.feature.model.Article;
import com.ss.android.article.base.feature.update.b.UpdateItemMgr;
import com.ss.android.article.base.feature.video.IVideoFullscreen;
import com.ss.android.article.base.ui.SwipeBackLayout;
import com.ss.android.article.base.utils.a.SharedPreferenceUtils;
import com.ss.android.article.browser.R;
import com.ss.android.common.app.IComponent;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.ui.view.SwipeOverlayFrameLayout;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.messagebus.SubscriptionRouter;
import com.ss.android.model.AbsArticle;
import com.ss.android.model.BaseArticle;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

public class NewDetailActivity extends com.bytedance.article.a.a.a<NewDetailPresenter> implements
        com.ss.android.article.base.feature.detail2.cc,
        com.ss.android.article.base.feature.detail2.h,
        com.ss.android.article.base.feature.detail2.view.f,
        DetailTitleBar.OnChildViewClickCallback,
        DetailToolBar.OnChildViewClickCallback {
    public ViewGroup mRoot;
    public SwipeBackLayout mSwipeBackLayout;
    public AppData mAppData;
    public DetailTitleBar mDetailTitleBar;
    public DetailToolBar mDetailToolBar;
    SSPage mSSPage;
    public boolean j;
    private SwipeOverlayFrameLayout mSwipeOverlayFrameLayout;
    private DetailTitleBarHelper mDetailTitleBarHelper;
    private DetailErrorView mDetailErrorView;
    private ViewStub mDetailErrorViewStub;
    private DeleteView mDeleteView;
    private ContextHolder p;
    private boolean q;

    public final void onBackClick() {
        if (this.mSSPage != null) {
            this.mSSPage.onBackClick();
        } else {
            this.finishPage();
        }
    }

    public final void onTopMoreTitleClick() {
        this.mPresenter.onEvent("click_more", "detail_top_bar");
        if (this.mSSPage == null
                || !this.mSSPage.isVisible()
                || ((this.mSSPage instanceof NewArticleDetailFragment))) {
            this.mPresenter.onTopMoreTitleClick(true);
        } else {
            this.mSSPage.onTopMoreTitleClick();
        }
    }

    public final void onCloseAllWebPageClick() {
        if (this.mSSPage != null && this.mSSPage.isVisible()) {
            this.mSSPage.onUserClickCloseBtn();
        }
    }

    public final void onWechatShareClick() {
        this.shareToWeChat("detail_top_bar_out", null);
    }

    public final void onQQShareClick() {
        this.shareToQQ("detail_top_bar_out", null);
    }

    public final void onMomentShareClick() {
        this.shareToMoment("detail_top_bar_out", null);
    }

    public final void onSharePlatformClick() {
        SharedPreferenceUtils.inst();
        int recentShareWay = SharedPreferenceUtils.getInt("recent_share_way");
        if (this.mSSPage == null || !this.mSSPage.isVisible() || ((this.mSSPage instanceof NewArticleDetailFragment))) {
            this.mPresenter.setSharePosition("detail_top_bar_out");
            this.mPresenter.share(recentShareWay, getArticle2());
            return;
        } else {
            this.mSSPage.onSharePlatformClick(recentShareWay);
        }
    }

    public final void onInfoBackClick() {
        if (this.mSSPage != null && (this.mSSPage.isVisible())) {
            this.mSSPage.onInfoBackClick();
        }
    }

    public final void onWriteCommentClick() {
        if (this.mSSPage == null || !this.mSSPage.isVisible()) {
            android.support.design.a.showImageToast(this, R.string.net_unvailable, 0);
        } else {
            this.mSSPage.onWriteCommentClick();
        }
    }

    public final void onFavorBtnClick() {
        this.mPresenter.mCommonBizInteractor.d();
    }

    public final void onCommentLayoutClick() {
        if (this.mSSPage == null || !this.mSSPage.isVisible()) {
            android.support.design.a.showImageToast(this, R.string.net_unvailable, 0);
        } else {
            this.mSSPage.onCommentLayoutClick();
        }
    }

    public final void onShare() {
        this.mPresenter.onEvent("detail_share_button", "detail_bottom_bar");
        if (this.mSSPage != null && this.mSSPage.isVisible() && !(this.mSSPage instanceof NewArticleDetailFragment)) {
            this.mSSPage.onShare();
        } else if (this.mAppData.getAbSettings().isQQTopShare()) {
            this.mPresenter.onTopMoreTitleClick(true);
        } else {
            this.mPresenter.onTopMoreTitleClick(false);
        }
    }

    public final Activity customGetActivity() {
        return this;
    }

    private void setupStatusBar() {
        if ((this.isGallery()) && !this.isGalleryFlat()) {
            this.mImmersedStatusBarHelper.setStatusBarResColor(com.ss.android.article.browser.R.color.status_bar_color_gallery);
        } else if (this.isVideo()) {
            this.mImmersedStatusBarHelper.setStatusBarResColor(com.ss.android.article.browser.R.color.status_bar_color_black);
        } else {
            this.mImmersedStatusBarHelper.setStatusBarResColor(com.ss.android.article.browser.R.color.status_bar_color_detail);
        }
    }

    private boolean isGallery() {
        return this.mPresenter.mNewDetailContext.isGallery();
    }

    private boolean isGalleryFlat() {
        return this.mPresenter.isGalleryFlat();
    }

    private boolean isVideo() {
        return this.mPresenter.mNewDetailContext.isVideo();
    }

    private boolean isNativePicGroup() {
        return this.mPresenter.mNewDetailContext.isNativePicGroup();
    }

    public static void startNewDetailActivity(Context context, Article article, long adId, String category) {
        if (article != null) {
            Intent intent = new Intent(context, NewDetailActivity.class);
            if (android.support.design.a.hasVideo(article)) {
                intent.setClass(context, NewVideoDetailActivity.class);
            }
            intent.putExtra("view_single_id", true);
            intent.putExtra("group_id", article.groupId);
            intent.putExtra("item_id", article.itemId);
            intent.putExtra("aggr_type", article.aggrType);
            intent.putExtra("group_flags", article.groupFlags);
            if (adId > 0) {
                intent.putExtra("ad_id", adId);
            }

            if (!android.support.design.a.isTextEmpty(category)) {
                intent.putExtra("category", category);
            }

            if (!(context instanceof Activity)) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            }
            context.startActivity(intent);
        }
    }

    public final void shareToWeChat(String sharePosition, JSONObject jsonObject) {
        if (this.mSSPage == null || !this.mSSPage.isVisible() || ((this.mSSPage instanceof NewArticleDetailFragment))) {
            this.mPresenter.setSharePosition(sharePosition);
            this.mPresenter.appendShareParams(jsonObject);
            this.mPresenter.share(2, this.getArticle2());
        } else {
            this.mSSPage.shareToWeChat(sharePosition, jsonObject);
        }
    }

    public final void saveShareWay(int shareWay) {
        if (shareWay >= 0 && this.mDetailToolBar != null) {
            this.mDetailToolBar.saveShareWay(shareWay);
        }
    }

    public final void setUserAvatar(String userAvatar) {
        this.mDetailTitleBar.setUserAvatar(userAvatar);
    }

    public final void setDetailStyle(DetailStyle detailStyle) {
        switch (detailStyle) {
            case NATIVE_PICGROUP_STYLE: {
                this.mDetailTitleBar.setTitleBarStyle(1);
                break;
            }
            case WAP_PICGROUP_STYLE: {
                this.mDetailTitleBar.setTitleBarStyle(2);
                break;
            }
        }
        this.mDetailToolBar.setToolBarStyle(detailStyle);
    }

    public final void startTitleAnim(int translationY, int startAlpha, int alpha) {
        this.mDetailTitleBar.animate().setDuration(200).translationY(((float) (-translationY))).alpha(((float) alpha));
        this.mDetailToolBar.animate().setDuration(200).translationY(((float) translationY)).alpha(((float) alpha));
        ValueAnimator valueAnimator = ValueAnimator.ofInt(new int[]{startAlpha, alpha});
        valueAnimator.setDuration(200).addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            public final void onAnimationUpdate(ValueAnimator animation) {
                android.support.design.a.setAlpha(((View) NewDetailActivity.this.mRoot), ((Integer) animation.getAnimatedValue()).intValue());
            }
        });
        valueAnimator.start();
    }

    @NonNull
    public final NewDetailPresenter createPresenter(Context context) {
        return new NewDetailPresenter(context);
    }

    @Override
    public final void onCreate() {
        super.a();
    }

    public final void a(Comment comment) {
        if (this.mSSPage != null && (this.mSSPage.isVisible())) {
            this.mSSPage.a(comment);
        }
    }

    public final void a(IVideoFullscreen videoFullscreen) {
        if (this.mSSPage != null && this.mSSPage.isVisible()) {
            this.mSSPage.a(videoFullscreen);
        }
    }

    public final void showContent(boolean hasContent) {
        if (!this.isFinishing() && !this.isDestroyed()) {
            if (!hasContent) {
                boolean isEmptyContent = this.mPresenter.mNewDetailContext.article == null
                        || this.mPresenter.mNewDetailContext.articleDetail == null
                        || TextUtils.isEmpty(this.mPresenter.mNewDetailContext.articleDetail.content);
                if (isEmptyContent) {
                    this.inflatDetailErrorView().showNoDataUI(this.isGallery());
                    return;
                }
            }
            this.inflatDetailErrorView().hideSelf();
            this.setDetailToolBarVisible(true);
            Fragment fragment;
            if (this.isVideo()) {//video
                fragment = new NewVideoDetailFragment();
                this.setDetailTitleBarVisible(false);
            } else if (this.isGallery() && !this.isGalleryFlat()) {//gallery
                this.mRoot.setBackgroundColor(-16777216);
                fragment = new GalleryFragment();
                this.findViewById(com.ss.android.article.browser.R.id.swipe_overlay_activity).setLayoutParams(new RelativeLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
                this.findViewById(com.ss.android.article.browser.R.id.root).requestLayout();
                DetailStyle detailStyle = this.isNativePicGroup() ? DetailStyle.NATIVE_PICGROUP_STYLE : DetailStyle.WAP_PICGROUP_STYLE;
                this.setDetailStyle(detailStyle);
                this.mDetailTitleBar.setOnUserAvatarClickListener((DetailTitleBar.OnUserAvatarClickListener) fragment);
            } else {//article
                this.mPresenter.buildArticleUrl();
                fragment = this.getSupportFragmentManager().findFragmentById(R.id.frame);
                if ((fragment instanceof NewArticleDetailFragment)) {
                    NewArticleDetailFragment detailFragment = (NewArticleDetailFragment) fragment;
                    this.mSSPage = detailFragment;
                    detailFragment.n();
                    return;
                }
                fragment = new NewArticleDetailFragment();
            }
            this.setupStatusBar();
            Intent intent = this.getIntent();
            if (intent != null) {
                this.mPresenter.appendContextParams(intent);
                fragment.setArguments(intent.getExtras());
            }
            this.mSSPage = (SSPage) fragment;
            FragmentTransaction fragmentTransaction = this.getSupportFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.frame, fragment);
            fragmentTransaction.commitAllowingStateLoss();
        }
    }

    public final boolean a(Article article) {
        return this.mSSPage != null && this.mSSPage.isVisible() && this.mSSPage.a(article);
    }

    public final boolean a(Article article, int arg3) {
        return this.mSSPage != null && this.mSSPage.isVisible() && this.mSSPage.a(article, arg3);
    }

    public final void switchToArticleDeleted(Article article) {
        this.mDeleteView.setVisibility(View.VISIBLE);
        this.mDetailTitleBar.setTitleBarStyle(3);
        this.mDetailTitleBar.init();
        this.setDetailTitleBarVisible(true);
        this.setDetailToolBarVisible(false);
        if ((this.isGallery()) && !this.isGalleryFlat()) {
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) this.findViewById(R.id.swipe_overlay_activity).getLayoutParams();
            layoutParams.addRule(2, R.id.tool_bar);
            layoutParams.addRule(3, R.id.title_bar);
        }

        Fragment fragment = this.getSupportFragmentManager().findFragmentById(com.ss.android.article.browser.R.id.frame);
        if (fragment != null) {
            FragmentTransaction fragmentTransaction = this.getSupportFragmentManager().beginTransaction();
            fragmentTransaction.remove(fragment);
            fragmentTransaction.commitAllowingStateLoss();
        }

        this.mSSPage = null;
        if (article != null) {
            article.delete = true;
            article.title = mPresenter.mContext.getString(com.ss.android.article.browser.R.string.info_article_deleted);
            article._abstract = "";
            article.commentCount = 0;
        }

        if (article != null) {
            UpdateItemMgr.getInstance(mPresenter.mContext).e(article.groupId);
        }
    }

    public final void setCommentCount(int commentCount) {
        this.mDetailToolBar.setCommentCount(commentCount);
    }

    public final void setFavorIconSelected(boolean favorIconSelected) {
        this.mDetailToolBar.setFavorIconSelected(favorIconSelected);
    }

    public final void shareToQQ(String sharePosition, JSONObject arg5) {
        if (this.mSSPage == null || !this.mSSPage.isVisible() || ((this.mSSPage instanceof NewArticleDetailFragment))) {
            this.mPresenter.setSharePosition(sharePosition);
            this.mPresenter.appendShareParams(arg5);
            this.mPresenter.share(3, this.getArticle2());
        } else {
            this.mSSPage.shareToQQ(sharePosition, arg5);
        }
    }

    public final void b(String arg2) {
        if (this.mDetailTitleBar != null) {
            this.mDetailTitleBar.setPictureTitleText(arg2);
        }
    }

    static Presenter b(NewDetailActivity arg1) {
        return ((b) arg1).mPresenter;
    }

    public final void initView() {
        this.mRoot = (ViewGroup) this.findViewById(com.ss.android.article.browser.R.id.root);
        this.mDetailTitleBar = (DetailTitleBar) this.findViewById(com.ss.android.article.browser.R.id.title_bar);
        this.mDetailToolBar = (DetailToolBar) this.findViewById(com.ss.android.article.browser.R.id.tool_bar);
        this.mDeleteView = (DeleteView) this.findViewById(com.ss.android.article.browser.R.id.delete_layout);
        this.mDetailErrorViewStub = (ViewStub) this.findViewById(com.ss.android.article.browser.R.id.detail_error_view_stub);
        this.mSwipeOverlayFrameLayout = (SwipeOverlayFrameLayout) this.findViewById(com.ss.android.article.browser.R.id.swipe_overlay_activity);
        this.mSwipeBackLayout = (SwipeBackLayout) this.findViewById(com.ss.android.article.browser.R.id.swipe_back_layout);
    }

    public final void setWriteCommentEnabled(boolean arg2) {
        this.mDetailToolBar.setWriteCommentEnabled(arg2);
    }

    public final void shareToMoment(String sharePosition, JSONObject appendParams) {
        if (this.mSSPage == null || !this.mSSPage.isVisible() || ((this.mSSPage instanceof NewArticleDetailFragment))) {
            this.mPresenter.setSharePosition(sharePosition);
            this.mPresenter.appendShareParams(appendParams);
            this.mPresenter.share(1, this.getArticle2());
        } else {
            this.mSSPage.shareToMoment(sharePosition, appendParams);
        }
    }

    static Presenter getPresenter(NewDetailActivity newDetailActivity) {
        return newDetailActivity.mPresenter;
    }

    public final void c() {
        JSONObject v3_2;
        JSONObject jsonObject;
        long v8;
        String v4;
        int v2;
        String v3;
        int v0;
        this.mAppData = AppData.getInstance();
        BaseArticle v1 = new BaseArticle(
                this.mPresenter.mNewDetailContextHolder.mNewDetailContext.group_id,
                this.mPresenter.mNewDetailContextHolder.mNewDetailContext.item_id,
                this.mPresenter.mNewDetailContextHolder.mNewDetailContext.aggrType);
        JSONObject v11 = this.mPresenter.mNewDetailContextHolder.mNewDetailContext.a();
        if (!this.mPresenter.mNewDetailContextHolder.mNewDetailContext.isGallery() && v11 != null) {
            v0 = this.mPresenter.mNewDetailContextHolder.mNewDetailContext.article == null
                    || this.mPresenter.mNewDetailContextHolder.mNewDetailContext.article.zzcomment == null
                    || (this.mPresenter.mNewDetailContextHolder.mNewDetailContext.article.zzcomment.isEmpty()) ? 0 : 1;
            try {
                v3 = "has_zz_comment";
                if (v0 != 0) {
                    v2 = 1;
                } else {
                    v2 = 0;
                }
                v11.put(v3, v2);
                if (v0 != 0) {
                    v11.put("mid", this.mPresenter.mNewDetailContextHolder.mNewDetailContext.article.zzcomment.get(0).mediaId);
                }
            } catch (JSONException jsonException) {
                jsonException.printStackTrace();
            }
        }

        if (AppData.getInstance().getAbSettings().isAppLogOld()) {
            v4 = "go_detail";
            v8 = this.mPresenter.mNewDetailContextHolder.mNewDetailContext.adId;
            String v5 = this.mPresenter.mNewDetailContextHolder.mNewDetailContext.getEnterFrom();
            if (android.support.design.a.isTextEmpty(v4)) {
            } else {

                long v2_1 = v1.itemId;
                v0 = v1.aggrType;
                if (v11 == null) {
                    jsonObject = new JSONObject();
                } else {
                    jsonObject = v11;
                }

                try {
                    if (!jsonObject.has("item_id")) {
                        jsonObject.put("item_id", v2_1);
                    }

                    if (!jsonObject.has("aggr_type")) {
                        jsonObject.put("aggr_type", v0);
                    }
                } catch (Exception exception) {
                }
                MobClickCombiner.onEvent(this.mPresenter.mNewDetailContextHolder.mContext, v4, v5, v1.groupId, v8, jsonObject);
            }
        }
        if (AppData.getInstance().getAbSettings().isAppLogNew()) {
            v4 = "go_detail";
            long v6 = this.mPresenter.mNewDetailContextHolder.mNewDetailContext.adId;
            String v2_2 = this.mPresenter.mNewDetailContextHolder.mNewDetailContext.getEnterFrom();
            if (android.support.design.a.isTextEmpty(v4)) {
                return;
            }

            String v0_3 = this.mPresenter.mNewDetailContextHolder.mNewDetailContext.categoryName;
            if (v2_2 != null) {
                if (v2_2.equals("click_" + this.mPresenter.mNewDetailContextHolder.mNewDetailContext.categoryName)) {
                    v2_2 = "click_category";
                    v0_3 = this.mPresenter.mNewDetailContextHolder.mNewDetailContext.categoryName;
                } else if (v2_2.equals("click_headline")) {
                    v0_3 = this.mPresenter.mNewDetailContextHolder.mNewDetailContext.categoryName;
                } else {
                    v0_3 = v2_2.replaceFirst("click_", "");
                }
            }

            v8 = v1.itemId;
            int v5_1 = v1.aggrType;
            if (v11 == null) {
                v3_2 = new JSONObject();
            } else {
                v3_2 = v11;
            }

            try {
                if (!v3_2.has("item_id")) {
                    v3_2.put("item_id", v8);
                }

                if (!v3_2.has("aggr_type")) {
                    v3_2.put("aggr_type", v5_1);
                }
            } catch (Exception v5_2) {
            }

            JSONObjectWrapper jsonObjectWrapper = new JSONObjectWrapper()
                    .put("group_id", Long.valueOf(v1.groupId))
                    .put("ad_id", Long.valueOf(v6))
                    .put("log_pb", this.mPresenter.mNewDetailContextHolder.mNewDetailContext.logPb)
                    .put("enter_from", v2_2)
                    .put("category_name", v0_3)
                    .put(v3_2);
            if (AppData.getInstance().getAbSettings().isApplogStaging()) {
                jsonObjectWrapper.put("_staging_flag", Integer.valueOf(1));
            }

            if (this.mPresenter.mNewDetailContextHolder.mNewDetailContext.searchResultId != 0) {
                jsonObjectWrapper.put("search_result_id", Long.valueOf(this.mPresenter.mNewDetailContextHolder.mNewDetailContext.searchResultId))
                        .put("source", this.mPresenter.mNewDetailContextHolder.mNewDetailContext.source)
                        .put("query", this.mPresenter.mNewDetailContextHolder.mNewDetailContext.query);
            }

            android.support.design.a.onEvent(v4, jsonObjectWrapper.jo);
        }
    }

    public final void startTitleBarAnimation(boolean isFadeOutAnimator) {
        if (mDetailTitleBarHelper.fadeInAnimatorListener == null) {
            mDetailTitleBarHelper.fadeInAnimatorListener = new Animator.AnimatorListener() {

                public final void onAnimationCancel(Animator animator) {
                }

                public final void onAnimationEnd(Animator animator) {
                    if (mDetailTitleBarHelper.newDetailPresenter.hasView()) {
                        mDetailTitleBarHelper.toggleBarEnable(true);
                    }
                }

                public final void onAnimationRepeat(Animator animator) {
                }

                public final void onAnimationStart(Animator animator) {
                    mDetailTitleBarHelper.toggleBarEnable(false);
                    UIUtils.setVisibility(mDetailTitleBarHelper.detailTitleBar, 0);
                    UIUtils.setVisibility(mDetailTitleBarHelper.detailToolBar, 0);
                }
            };
        }

        if (mDetailTitleBarHelper.fadeOutAnimationListener == null) {
            mDetailTitleBarHelper.fadeOutAnimationListener = new Animator.AnimatorListener() {

                public final void onAnimationCancel(Animator animator) {
                }

                public final void onAnimationEnd(Animator animator) {
                    if (mDetailTitleBarHelper.newDetailPresenter.hasView()) {
                        mDetailTitleBarHelper.toggleBarEnable(true);
                        if (mDetailTitleBarHelper.detailTitleBar.getAlpha() == 0f) {
                            UIUtils.setVisibility(mDetailTitleBarHelper.detailTitleBar, View.INVISIBLE);
                        }

                        if (mDetailTitleBarHelper.detailToolBar.getAlpha() == 0f) {
                            UIUtils.setVisibility(mDetailTitleBarHelper.detailToolBar, View.INVISIBLE);
                        }

                        mDetailTitleBarHelper.detailTitleBar.setAlpha(1f);
                        mDetailTitleBarHelper.detailToolBar.setAlpha(1f);
                    }
                }

                public final void onAnimationRepeat(Animator animator) {
                }

                public final void onAnimationStart(Animator animator) {
                    mDetailTitleBarHelper.toggleBarEnable(false);
                }
            };
        }

        if (isFadeOutAnimator) {
            if (mDetailTitleBarHelper.fadeOutAnimator == null) {
                mDetailTitleBarHelper.fadeOutAnimator = ValueAnimator.ofFloat(new float[]{1f, 0f});
                mDetailTitleBarHelper.fadeOutAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                        float floatValue = ((Float) valueAnimator.getAnimatedValue()).floatValue();
                        mDetailTitleBarHelper.detailTitleBar.setAlpha(floatValue);
                        mDetailTitleBarHelper.detailToolBar.setAlpha(floatValue);
                    }
                });
                mDetailTitleBarHelper.fadeOutAnimator.setDuration(400L);
                mDetailTitleBarHelper.fadeOutAnimator.addListener(mDetailTitleBarHelper.fadeOutAnimationListener);
            }

            mDetailTitleBarHelper.fadeOutAnimator.start();
        } else {
            if (mDetailTitleBarHelper.fadeInAnimator == null) {
                mDetailTitleBarHelper.fadeInAnimator = ValueAnimator.ofFloat(new float[]{0f, 1f});
                mDetailTitleBarHelper.fadeInAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                        float floatValue = ((Float) valueAnimator.getAnimatedValue()).floatValue();
                        mDetailTitleBarHelper.detailTitleBar.setAlpha(floatValue);
                        mDetailTitleBarHelper.detailToolBar.setAlpha(floatValue);
                    }
                });
                mDetailTitleBarHelper.fadeInAnimator.setDuration(400L);
                mDetailTitleBarHelper.fadeInAnimator.addListener(mDetailTitleBarHelper.fadeInAnimatorListener);
            }
            mDetailTitleBarHelper.fadeInAnimator.start();
        }
    }

    public final void d() {
        AppData.isNightMode();
        this.mRoot.setBackgroundResource(com.ss.android.article.browser.R.color.c);
        this.mDetailTitleBar.setOnChildViewClickCallback(this);
        this.mDetailToolBar.setOnChildViewClickCallback(this);
        this.mDeleteView.setVisibility(View.GONE);
        this.mDetailTitleBarHelper = new DetailTitleBarHelper(this.mPresenter, this.mDetailTitleBar, this.mDetailToolBar);
        if (!this.isGallery() || (this.isGalleryFlat())) {
            this.mSwipeBackLayout.setEnabled(false);
        } else {
            this.mRoot.setBackgroundResource(com.ss.android.article.browser.R.color.gallery_detail_item_bg);
            if (this.isNativePicGroup()) {
                this.mDetailTitleBar.setTitleBarStyle(1);
                this.mDetailToolBar.setToolBarStyle(DetailStyle.NATIVE_PICGROUP_STYLE);
            } else {
                this.mDetailTitleBar.setTitleBarStyle(2);
                this.mDetailToolBar.setToolBarStyle(DetailStyle.WAP_PICGROUP_STYLE);
            }

            this.mSwipeBackLayout.setEnabled(this.mAppData.getAbSettings().isSwipeBackEnabled());
        }

        if (this.getArticle2() != null) {
            this.setFavorIconSelected(this.getArticle2().userRepin);
        } else {
            this.hideMoreBtn();
            this.setDetailToolBarVisible(false);
        }

        this.mDetailTitleBar.b();
        if (AppData.getInstance().getAbSettings().isBottomShare()) {
            ((NewDetailPresenter) this.mPresenter).mCommonBizInteractor.mShareWaySaver = new CommonBizInteractor.ShareWaySaver(this);
        }
    }

    public final void e(boolean arg3) {
        if ((AppData.getInstance().getAbSettings().isTopShare()) || (AppData.getInstance().getAbSettings().isQQTopShare())) {
            this.mDetailTitleBar.setUserVerifiedIconVisible(false);
        } else {
            this.mDetailTitleBar.setUserVerifiedIconVisible(arg3);
        }
    }

    public final void e() {
        this.mSwipeOverlayFrameLayout.setOnSwipeListener(new SwipeOverlayFrameLayout.OnSwipeBackListener() {

            public final boolean onSwipeBack() {
                boolean v0;
                if (NewDetailActivity.this.mSSPage == null || !NewDetailActivity.this.mSSPage.isVisible()) {
                    NewDetailActivity.this.finishPage();
                    v0 = true;
                } else {
                    v0 = false;
                }
                return v0;
            }

            public final boolean b() {
                return false;
            }
        });
    }

    public final void setDetailTitleBarVisible(boolean visible) {
        if (mDetailTitleBarHelper.fadeOutAnimator != null && (mDetailTitleBarHelper.fadeOutAnimator.isRunning())) {
            mDetailTitleBarHelper.fadeOutAnimator.cancel();
        }
        int visibility = visible ? View.VISIBLE : View.GONE;
        UIUtils.setVisibility(mDetailTitleBarHelper.detailTitleBar, visibility);
    }

    public final AbsArticle getArticle() {
        AbsArticle absArticle;
        if (this.mSSPage == null || !this.mSSPage.isVisible()) {
            absArticle = this.getArticle2();
        } else {
            absArticle = this.mSSPage.getArticle();
        }

        return absArticle;
    }

    public void finish() {
        super.finish();
        if (this.q) {
            this.overridePendingTransition(0, R.anim.aa);
        }
    }

    public final void setDetailToolBarVisible(boolean visible) {
        if (mDetailTitleBarHelper.fadeOutAnimator != null && (mDetailTitleBarHelper.fadeOutAnimator.isRunning())) {
            mDetailTitleBarHelper.fadeOutAnimator.cancel();
        }

        int visibility = visible ? View.VISIBLE : View.GONE;
        UIUtils.setVisibility(mDetailTitleBarHelper.detailToolBar, visibility);
    }

    public final long getArticleId() {
        long v0 = this.mSSPage == null || !this.mSSPage.isVisible() ? 0 : this.mSSPage.getArticleId();
        return v0;
    }

    public final void h(boolean arg6) {
        int v0 = 0;
        int v4 = 8;
        AppData.isNightMode();
        DetailToolBar v2 = this.mDetailToolBar;
        if (AppData.getInstance().getAbSettings().isVideoDetailRelatedButtonEnabled()) {
            if (arg6) {
                if (v2.mActionViewUp.getVisibility() != View.VISIBLE || v2.mActionCommentLayout.getVisibility() != View.GONE) {
                    UIUtils.setVisibility(v2.mActionViewUp, 0);
                    UIUtils.setVisibility(v2.mActionCommentLayout, v4);
                    v0 = 1;
                }

                v2.mActionViewUp.setImageResource(com.ss.android.article.browser.R.drawable.f3);
                if (!v2.h) {
                    return;
                }

                if (v0 == 0) {
                    return;
                }

                v2.mActionViewUp.startAnimation(v2.i);
                v2.mActionCommentLayout.startAnimation(v2.k);
            } else {
                if (v2.mActionViewUp.getVisibility() != View.GONE || v2.mActionCommentLayout.getVisibility() != View.VISIBLE) {
                    UIUtils.setVisibility(v2.mActionViewUp, v4);
                    UIUtils.setVisibility(v2.mActionCommentLayout, 0);
                    v0 = 1;
                }

                v2.mActionCommentCountTv.setText(String.valueOf(v2.mCommentCount));
                v2.mActionViewCommentIv.setImageResource(com.ss.android.article.browser.R.drawable.ic_action_comment);
                if (!v2.h) {
                    return;
                }

                if (v0 == 0) {
                    return;
                }

                v2.mActionViewUp.startAnimation(v2.l);
                v2.mActionCommentLayout.startAnimation(v2.j);
            }
        }
    }

    public final int getCommentMode() {
        int v0;
        if (this.mSSPage != null && (this.mSSPage.isVisible())) {
            v0 = this.mSSPage.getCommentMode();
        } else if (this.getArticle2() == null) {
            v0 = 0;
        } else {
            v0 = this.getArticle2().getCommentMode();
        }

        return v0;
    }

    public final int i() {
        int v0 = this.mSSPage == null || !this.mSSPage.isVisible() ? 0 : this.mSSPage.i();
        return v0;
    }

    public final long j() {
        long v0 = this.mSSPage == null || !this.mSSPage.isVisible() ? 0 : this.mSSPage.j();
        return v0;
    }

    public final int k() {
        int v0 = this.mSSPage == null || !this.mSSPage.isVisible() ? 0 : this.mSSPage.k();
        return v0;
    }

    public final String l() {
        return "detail";
    }

    public final void m() {
        DetailErrorView v1 = this.inflatDetailErrorView();
        boolean v0 = !this.isGallery() || (this.isGalleryFlat()) ? false : true;
        v1.showNoDataUI(v0);
    }

    public final void showDetailErrorView() {
        this.inflatDetailErrorView().showLoadingView();
    }

    public final Article getArticle2() {
        return this.mPresenter.mNewDetailContext.article;
    }

    public void onAddressEditClicked(View view) {
        String v3;
        int v0;
        if (this.p == null) {
            this.p = new ContextHolder(this, this.mPresenter.mNewDetailContext);
        }

        final ContextHolder v6 = this.p;
        if (!Logger.debug()) {
            if (v6.mAppData != null && (v6.mAppData.aD())) {
                v0 = 1;
            } else {
                v0 = 0;
            }
        } else {
            label_17:
            v0 = 1;
        }

        if (v0 != 0) {
            final Dialog addressEditDialog = new Dialog(v6.mActivity, R.style.address_bar_dialog);
            View addrEditDialogView = LayoutInflater.from(v6.mActivity).inflate(com.ss.android.article.browser.R.layout.addr_edit_dialog, null);
            View addressLayout = addrEditDialogView.findViewById(com.ss.android.article.browser.R.id.address_layout);
            final View addressEdit = addrEditDialogView.findViewById(com.ss.android.article.browser.R.id.address_edit);
            View addressStopBtn = addrEditDialogView.findViewById(com.ss.android.article.browser.R.id.address_stop_btn);
            View addrBarCancel = addrEditDialogView.findViewById(com.ss.android.article.browser.R.id.addr_bar_cancel);
            if (v6.mNewDetailContext == null || v6.mNewDetailContext.article == null) {
                v3 = "";
            } else if (!TextUtils.isEmpty(v6.mNewDetailContext.article.displayUrl)) {
                v3 = v6.mNewDetailContext.article.displayUrl;
            } else if (!TextUtils.isEmpty(v6.mNewDetailContext.article.url)) {
                v3 = v6.mNewDetailContext.article.url;
            } else {
                v3 = v6.mNewDetailContext.article.articleUrl;
            }

            if (v3 == null) {
                v3 = "";
            }

            v3 = String.valueOf(v3);
            ((EditText) addressEdit).setText(v3);
            ((EditText) addressEdit).selectAll();
            ((EditText) addressEdit).setSelection(v3.length());
            AppData.isNightMode();
            addrEditDialogView.setBackgroundResource(com.ss.android.article.browser.R.drawable.detail_bg_titlebar);
            UIUtils.setBackgroundResource(addressLayout, R.drawable.detail_titlebar_edit_bg);
            ((EditText) addressEdit).setTextColor(v6.mActivity.getResources().getColor(com.ss.android.article.browser.R.color.detail_title_bar_url));
            ((ImageView) addressStopBtn).setImageResource(com.ss.android.article.browser.R.drawable.titlebar_refresh_detail_cancel);
            ((TextView) addrBarCancel).setCompoundDrawablesWithIntrinsicBounds(com.ss.android.article.browser.R.drawable.btn_back, 0, 0, 0);
            ((EditText) addressEdit).setOnEditorActionListener(new TextView.OnEditorActionListener() {

                public final boolean onEditorAction(
                        TextView textView,
                        int arg6,
                        KeyEvent keyEvent) {
                    String v3 = null;
                    if (6 == arg6 || arg6 == 0) {
                        Logger.d(ContextHolder.TAG, "action id is " + arg6);
                        String v0 = ((EditText) addressEdit).getText().toString();
                        if (!TextUtils.isEmpty(v0)) {
                            if (TTUtils.isValidUrl(v0)) {
                                android.support.design.a.b(v6.mActivity, v0, v3);
                            } else {
                                android.support.design.a.b(v6.mActivity, "http://" + v0, v3);
                            }
                        }

                        addressEditDialog.dismiss();
                    }
                    return true;
                }
            });
            addressStopBtn.setOnClickListener(new View.OnClickListener() {

                public final void onClick(View arg3) {
                    ((EditText) addressEdit).setText("");
                }
            });
            addrBarCancel.setOnClickListener(new View.OnClickListener() {
                public final void onClick(View arg2) {
                    addressEditDialog.dismiss();
                }
            });
            addressEditDialog.getWindow().setGravity(48);
            addressEditDialog.getWindow().setLayout(-1, -2);
            addressEditDialog.getWindow().setSoftInputMode(5);
            addressEditDialog.setContentView(addrEditDialogView);
            addressEditDialog.setCanceledOnTouchOutside(true);
            addressEditDialog.show();
        }
    }

    public void onBackPressed() {
        if (this.mSSPage != null) {
            this.mSSPage.onBack();
        } else {
            this.finishPage();
        }
    }

    public void onCreate(Bundle savedInstanceState) {
        if (Build.VERSION.SDK_INT >= 17) {
            this.getWindow().addFlags(16777216);
        }
        this.requestWindowFeature(10);
        super.onCreate(savedInstanceState);
        if (!this.isFinishing()) {
            int v0;
            if (this.isGallery() && !this.isGalleryFlat()) {
                v0 = 0;
            } else if (!this.isVideo()) {
                v0 = 1;
            } else {
                v0 = 0;
            }

            if (v0 == 0 || (this.mAppData.getAppSettings().disableDetailFragmentPreload())) {
                this.mPresenter.f();
            } else {
                NewArticleDetailFragment newArticleDetailFragment = new NewArticleDetailFragment();
                Intent intent = this.getIntent();
                if (intent != null) {
                    this.mPresenter.appendContextParams(intent);
                    newArticleDetailFragment.setArguments(intent.getExtras());
                }
                FragmentTransaction fragmentTransaction = this.getSupportFragmentManager().beginTransaction();
                fragmentTransaction.replace(com.ss.android.article.browser.R.id.frame, newArticleDetailFragment);
                fragmentTransaction.commitAllowingStateLoss();
                this.getWindow().getDecorView().post(new Runnable() {

                    public final void run() {
                        NewDetailActivity.this.mPresenter.f();
                    }
                });
            }

            if (AppData.getInstance().getAbSettings().isSwipeBackEnabled()
                    && this.isGallery()
                    && !this.isGalleryFlat()) {
                this.q = true;
                this.mDelayOverrideActivityTrans = true;
                this.overridePendingTransition(R.anim.a3, 0);
            }
        }
        this.setupStatusBar();
        ActivityStackManager.addActivity(Type.DETAIL_ACTIVITY, this);
    }

    public void onDestroy() {
        super.onDestroy();
        if (this.mDetailTitleBar != null) {
            this.mDetailTitleBar.f();
        }
    }

    public void onPause() {
        super.onPause();
        SubscriptionRouter.removeSubscriber(this.mDetailTitleBar);
    }

    public void onResume() {
        super.onResume();
        this.mDetailTitleBar.g();
        SubscriptionRouter.addSubscriber(this.mDetailTitleBar);
    }

    public void onStop() {
        super.onStop();
        if (this.mDetailErrorView != null) {
            if (mDetailErrorView.mNoNetView != null) {
                mDetailErrorView.mNoNetView.b();
            }
        }
    }

    public final NewDetailContext getNewDetailContext() {
        return this.mPresenter.mNewDetailContext;
    }

    public final DetailErrorView inflatDetailErrorView() {
        if (this.mDetailErrorView == null) {
            this.mDetailErrorView = (DetailErrorView) this.mDetailErrorViewStub.inflate();
            this.mDetailErrorView.setOnRetryClickListener(new View.OnClickListener() {
                public final void onClick(View view) {
                    Article v3;
                    String v1;
                    Article article = mPresenter.mNewDetailContext.article;
                    if ((mPresenter.mNewDetailContext.viewSingleId) || article != null) {
                        if (mPresenter.hasView()) {
                            mPresenter.mView.showDetailErrorView();

                        }

                        if (article != null) {
                            v1 = article.getItemKey();
                            v3 = article;
                        } else {
                            String v0 = Article.a(mPresenter.mNewDetailContext.group_id, mPresenter.mNewDetailContext.item_id);
                            v3 = new Article(mPresenter.mNewDetailContext.group_id,
                                    mPresenter.mNewDetailContext.item_id,
                                    mPresenter.mNewDetailContext.aggrType);
                            v1 = v0;
                        }

                        mPresenter.mDetailLoadResultHandler.loadArticleDetail(v1, article, v3, false, mPresenter.mLoadArticleDetailResultListener);
                    }
                }
            });
        }
        return this.mDetailErrorView;
    }

    public final ArticleDetail getArticleDetail() {
        return this.mPresenter.mNewDetailContext.articleDetail;
    }

    public final void cleanFavorIvAnimation() {
        this.mDetailToolBar.mActionFavorIv.clearAnimation();
    }

    public void startActivityForResult(final Intent arg5, int arg6, Bundle arg7) {
        super.startActivityForResult(arg5, arg6, arg7);
        this.mRoot.postDelayed(new Runnable() {

            public final void run() {
                Presenter v0 = NewDetailActivity.getPresenter(NewDetailActivity.this);
                Intent v1 = arg5;
                if (v1 != null) {
                    Uri v2 = v1.getData();
                    ComponentName v1_1 = v1.getComponent();
                    if (v2 != null && v1_1 != null) {
                        String v2_1 = v2.getHost();
                        String v1_2 = v1_1.getClassName();
                        if (!TextUtils.isEmpty(v2_1) && !TextUtils.isEmpty(((CharSequence) v1_2)) && (v2_1.equals("detail")) && (v1_2.equals(AdsAppActivity.class.getName())) && ((NewDetailPresenter) v0).mNewDetailContext.articleDetail != null && ((NewDetailPresenter) v0).mNewDetailContext.articleDetail.novelData != null && (((NewDetailPresenter) v0).hasView())) {
                            ((NewDetailPresenter) v0).mView.finish();
                        }
                    }
                }
            }
        }, 1000);
    }

    public final IComponent getComponent() {
        return this;
    }

    public final SSPage getSSPage() {
        return this.mSSPage;
    }

    public final String v() {
        String v0 = "article_detail_favor";
        if (this.mSSPage != null && (this.mSSPage.isVisible())) {
            if ((this.mSSPage instanceof NewArticleDetailFragment)) {
                v0 = "article_detail_favor";
            } else if ((this.mSSPage instanceof NewVideoDetailFragment)) {
                v0 = "video_detail_favor";
            } else if ((this.mSSPage instanceof GalleryFragment)) {
                v0 = "photo_detail_favor";
            }
        }

        return v0;
    }

    public final ArticleInfo getArticleInfo() {
        return null;
    }

    public final void finishPage() {
        int v4 = 0;
        if (!this.isGallery()) {
            this.isVideo();
        }
        if (mPresenter.hasView()) {
            if (!mPresenter.mNewDetailContext.viewSingleId) {
                mPresenter.mView.setResult(-1, new Intent());
                mPresenter.mView.finish();
                return;
            }

            boolean notStayTT = mPresenter.mNewDetailContext.stayTT == 0;
            Intent intent = !mPresenter.mView.isTaskRoot() || notStayTT
                    ? null
                    : ToolUtils.getLaunchIntentForPackage(mPresenter.mContext, mPresenter.mView.getPackageName());
            if (intent != null) {
                mPresenter.mView.finish();
                if (mPresenter.mAppData != null) {
                    System.currentTimeMillis();
                    AppData.ah();
                }

                intent.putExtra("quick_launch", true);
                mPresenter.mView.startActivity(intent);
                return;
            }

            if (notStayTT
                    && mPresenter.mNewDetailContext.previousTaskId > 0
                    && !android.support.design.a.isTextEmpty(mPresenter.mNewDetailContext.previousTaskIntent)) {
                try {
                    List<ActivityManager.RecentTaskInfo> recentTaskInfoList = ((ActivityManager) mPresenter.mContext.getSystemService(Context.ACTIVITY_SERVICE)).getRecentTasks(2, 2);
                    ActivityManager.RecentTaskInfo recentTaskInfo = null;
                    if (recentTaskInfoList != null && recentTaskInfoList.size() > 1) {
                        recentTaskInfo = recentTaskInfoList.get(1);
                    }

                    if (recentTaskInfo != null && recentTaskInfo.id == mPresenter.mNewDetailContext.previousTaskId) {
                        mPresenter.mView.finish();
                        mPresenter.mView.startActivity(
                                Intent.parseUri(
                                        mPresenter.mNewDetailContext.previousTaskIntent,
                                        Intent.URI_INTENT_SCHEME));
                        v4 = 1;
                    }
                } catch (Exception exception) {
                    exception.printStackTrace();
                }
            }
            if (v4 == 0) {
                mPresenter.mView.finish();
                return;
            }
        }
    }

    public final int getDetailTitleBarHeight() {
        return this.mDetailTitleBar == null || this.mDetailTitleBar.getVisibility() != View.VISIBLE
                ? 0
                : this.mDetailTitleBar.getHeight();
    }

    public final void hideMoreBtn() {
        this.mDetailTitleBar.setMoreBtnVisibility(false);
    }
}

